package com.example.neteasecloudmusic.ui.dicovery;

import com.example.neteasecloudmusic.bean.discoveryBean.Bean;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.schedulers.Schedulers;

public class DiscoveryPresenter implements DiscoveryContract.IDiscoveryPresenter {

    private DiscoveryContract.IDiscoveryView discoveryView;
    private DiscoveryContract.IDiscoveryModel discoveryModel;

    public DiscoveryPresenter(DiscoveryContract.IDiscoveryView discoveryView) {
        this.discoveryView = discoveryView;
        discoveryModel = new DiscoveryModel();
    }

    @Override
    public void getData() {
        discoveryModel.getData().subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(new Consumer<Bean>() {
            @Override
            public void accept(Bean bean) throws Throwable {
                discoveryView.getBeanSuccess(bean.getBlocks());
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Throwable {
                discoveryView.getBeanFailure(throwable);
            }
        });
    }
}
